<script setup lang="ts">
import {onMounted, ref} from "vue";
import {useRoute} from "vue-router";
import requestApi from "../plugins/requestApi.ts";
import {showToast} from "vant";
import qs from "qs"
import {CurrentUser} from "../models/user";
import UserCardList from "../components/UserCardList.vue";

const route = useRoute();
const {tags} = route.query;
const userList = ref([]);
onMounted(() => {
  requestApi.get<CurrentUser[]>('/user/search/tags', {
    params: {
      tagNameList: tags
    },
    paramsSerializer: {
      serialize: params => {
        return qs.stringify(params, {arrayFormat: 'repeat'})
      }
    }
  }).then(res => {
    if (res) {
      res.forEach(user => {
        if (user.tags){
          user.tags = JSON.parse(user.tags);
        }
      })
    }
    console.log(res)
    userList.value = res;
    showToast("请求成功");
  }).catch((err) => {
    showToast("请求失败");
  })
})

</script>

<template>
  <UserCardList :userList="userList"/>
  <van-empty v-if="userList.length < 1 || !userList"  description="搜索结果为空"/>
</template>

<style scoped>

</style>